import request from '@/utils/request'
import { getToken } from '@/utils/auth'

var transformMethod = function(data) {
  let ret = ''
  for (const it in data) {
    ret += encodeURIComponent(it) + '=' + encodeURIComponent(data[it]) + '&'
  }
  return ret
}

// 获取价签
export function getCharge(params) {
  return request({
    url: '/wxh-cloud-rest/rest/' + getToken() + '/charge/list',
    method: 'get',
    params: params
  })
}

// 保存价签
export function saveCharge(params) {
  return request({
    url: '/wxh-cloud-rest/rest/' + getToken() + '/charge/save',
    method: 'POST',
    headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
    transformRequest: [transformMethod],
    data: params
  })
}

// 获取保外价签价签
export function getOutCharge() {
  return request({
    url: '/wxh-cloud-rest/rest/' + getToken() + '/charge/outlist',
    method: 'get'
  })
}

// 保存价签
export function saveOutCharge(params) {
  return request({
    url: '/wxh-cloud-rest/rest/' + getToken() + '/charge/outSave',
    method: 'post',
    headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
    transformRequest: [transformMethod],
    data: params
  })
}

// 获取其他服务项目价签
export function getOtherCharge(params) {
  return request({
    url: '/wxh-cloud-rest/rest/' + getToken() + '/charge/otherlistByParentType',
    method: 'get',
    params: params
  })
}

// 保存其他服务价签价签
export function saveOtherCharge(params) {
  return request({
    url: '/wxh-cloud-rest/rest/' + getToken() + '/charge/otherSave',
    method: 'post',
    headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
    transformRequest: [transformMethod],
    data: params
  })
}
